﻿(function($) {
	$(window).load(function() {		
		note_demo();
	})
})(jQuery);


function note_demo(){
	var username = $.session.get("username");
	var secretkey = $.session.get("user_secretkey");
	$.ajax({
		url: "../../../service",
		cache : false,
		data : {
			proc : "g_xmy.wx_public",
			para : "['" + username + "','" + secretkey + "']"
		},
		dataType : "json",
		success : function(data) {
			if (data[0].TAG == "0") {
				window.location.href="./error.html";
			} else {
				
				for(var a=0;a<data.length;a++){
					document.getElementById("wx_name").value = data[0].WX_NAME;
					document.getElementById("wx_ms").value = data[0].DESCRIBE;
					document.getElementById("wx_number").value = data[0].PUBLIC_ACCOUNT;
					document.getElementById("ys_id").value = data[0].ORIGINAL_ID;
					document.getElementById("wx_type").value = data[0].TYPE;
					document.getElementById("app_id").value = data[0].APPID;
					document.getElementById("app_key").value = data[0].SECRET;
					document.getElementById("wx_url").value = window.location.host+'/api.jsp?id=1';
					document.getElementById("wx_token").value = data[0].TOKEN;
					document.getElementById("wx_Ekey").value = data[0].ENCODINGAESKEY;
					
				}
			}
		}
	});
}


//随机生成Token
function add_token(){
	var len = len || 32;
	var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz0123456789';
	var maxPos = $chars.length;
	var pwd = '';
	for (i = 0; i < len; i++) {
		pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
	}
	document.getElementById("wx_token").value = pwd;
	return pwd;

}

//随机生成EncodingAESKey
function add_AESKey(){
	var len2 = len2 || 43;
	var $chars2 = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz0123456789';
	var maxPos2 = $chars2.length;
	var pwd2 = '';
	for (i2 = 0; i2 < len2; i2++) {
		pwd2 += $chars2.charAt(Math.floor(Math.random() * maxPos2));
	}
	document.getElementById("wx_Ekey").value = pwd2;
	return pwd2;

}

function update_public(){
	var username = $.session.get("username");
	var secretkey = $.session.get("user_secretkey");

	var wx_name = document.getElementById("wx_name").value;
	var wx_ms = document.getElementById("wx_ms").value;
	var wx_number = document.getElementById("wx_number").value;
	var ys_id = document.getElementById("ys_id").value;
	var wx_type = document.getElementById("wx_type").value;
	var app_id = document.getElementById("app_id").value;
	var app_key = document.getElementById("app_key").value;
	var wx_url = document.getElementById("wx_url").value;
	var wx_token = document.getElementById("wx_token").value;
	var wx_Ekey = document.getElementById("wx_Ekey").value;
	console.log(username + "','" + secretkey + "','" + wx_name + "','" + wx_ms + "','" + wx_number + "','" + ys_id + "','" + 
					wx_type + "','" + app_id + "','" + app_key + "','" + wx_url + "','" + wx_token + "','" + wx_Ekey);

	$.ajax({
		url: "../../../service",
		cache : false,
		data : {
			proc : "g_xmy.up_public",
			para : "['" + username + "','" + secretkey + "','" + wx_name + "','" + wx_ms + "','" + wx_number + "','" + ys_id + "','" + 
					wx_type + "','" + app_id + "','" + app_key + "','" + wx_url + "','" + wx_token + "','" + wx_Ekey +"']"
		},
		dataType : "json",
		success : function(data) {
			console.log(JSON.stringify(data));
			if (data[0].TAG == "1") {
				layer.alert("微信公众号修改成功!",function(index){
					 window.location.href="./the_public.html";
					 layer.close(index);
				}); 
			} else {
				layer.alert("短信配置保存失败，请联系程序员！");
			}
		}
	});
}










